package com.shawn.mobliesafe;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;


public class SetUp4Activity extends SetUpBaseActivity {

    private CheckBox cb_setup4_protected;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_up4);
        cb_setup4_protected = (CheckBox)findViewById(R.id.cb_setup4_protected);
        
        if(sp.getBoolean("protected",false)) {
            cb_setup4_protected.setText("您已经开启了防盗保护");
            cb_setup4_protected.setChecked(true);//必须要写
        }else {
            cb_setup4_protected.setText("您还没有开启防盗保护");
            cb_setup4_protected.setChecked(false);//必须要写
        }

        cb_setup4_protected.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferences.Editor editor = sp.edit();
                if(isChecked) {
                    cb_setup4_protected.setText("您已经开启了防盗保护");
                    cb_setup4_protected.setChecked(true);
                    editor.putBoolean("protected",true);
                }else {
                    cb_setup4_protected.setText("您还没有开启防盗保护");
                    cb_setup4_protected.setChecked(false);
                    editor.putBoolean("protected", false);
                }
                editor.commit();
            }
        });
    }

    @Override
    public void next_activity() {
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean("first", false);
        editor.commit();
        Intent intent = new Intent(this,LostfindActivity.class);
        startActivity(intent);
        finish();
    }

    @Override
    public void pre_activity() {
        Intent intent = new Intent(this,SetUp3Activity.class);
        startActivity(intent);
        finish();
        overridePendingTransition(R.anim.setup_enter_pre, R.anim.setup_exit_pre);
    }
}
